package com.sgcc.nfc.lock.data.local.mapper

import com.sgcc.nfc.lock.data.local.entity.LockEntity
import com.sgcc.nfc.lock.domain.model.Lock
import com.sgcc.nfc.lock.domain.model.LockStatus
import com.sgcc.nfc.lock.domain.model.LockType

fun LockEntity.toDomain(): Lock = Lock(
    lockId = lockId,
    lockName = lockName,
    lockNfcId = lockNfcId,
    lockType = when (lockType) {
        0 -> LockType.NFC_LOCK
        1 -> LockType.SMART_LOCK
        else -> LockType.UNKNOWN
    },
    status = LockStatus.from(status),
    batteryLevel = batteryLevel,
    lastHeartbeat = lastHeartbeat,
    roomId = roomId,
    roomName = roomName,
    latitude = latitude,
    longitude = longitude,
    address = address
)

fun Lock.toEntity(): LockEntity = LockEntity(
    lockId = lockId,
    lockName = lockName,
    lockNfcId = lockNfcId,
    lockType = when (lockType) {
        LockType.NFC_LOCK -> 0
        LockType.SMART_LOCK -> 1
        LockType.UNKNOWN -> -1
    },
    status = status.code,
    batteryLevel = batteryLevel,
    lastHeartbeat = lastHeartbeat,
    roomId = roomId,
    roomName = roomName,
    latitude = latitude,
    longitude = longitude,
    address = address
)